package com.fr.web.core.service;

import com.fr.base.FRContext;
import com.fr.base.core.util.TemplateUtils;
import com.fr.chart.ChartPainter;
import com.fr.util.Utils;
import com.fr.web.core.WebUtils;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ChartHtmlService extends NoSessionIDService
{
  private static ChartHtmlService chartService = new ChartHtmlService();
  private String startWidth = "chart";
  private String chartop = "charthtml";
  private String selectedop = "chartselected";
  private static Map jsMap = new HashMap();
  private static String chartHtmlPoistion = "/com/fr/web/core/js/ChartPaintHtml.html";

  public static ChartHtmlService getInstance()
  {
    return chartService;
  }

  public boolean accept(String paramString)
  {
    return paramString.startsWith(this.startWidth);
  }

  public void process(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse, String paramString)
    throws Exception
  {
    if (this.chartop.equals(paramString))
      dealWidthChartPaintHtml(paramHttpServletRequest, paramHttpServletResponse);
    else if (this.selectedop.equals(paramString))
      dealWithChartPaint(paramHttpServletRequest, paramHttpServletResponse);
  }

  private static void dealWidthChartPaintHtml(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    Object localObject = jsMap.get(WebUtils.getHTTPRequestParameter(paramHttpServletRequest, "chartID"));
    try
    {
      TemplateUtils.dealWithTemplate(chartHtmlPoistion, paramHttpServletResponse, (Map)localObject);
    }
    catch (IOException localIOException)
    {
      FRContext.getLogger().log(Level.WARNING, localIOException.getMessage(), localIOException);
    }
  }

  private void dealWithChartPaint(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    String str1 = WebUtils.getHTTPRequestParameter(paramHttpServletRequest, "chartPaintID");
    Object localObject = jsMap.get(str1);
    if (localObject instanceof Map)
    {
      Map localMap = (Map)localObject;
      ChartPainter localChartPainter = (ChartPainter)localMap.get("chartPaint");
      String str2 = WebUtils.getHTTPRequestParameter(paramHttpServletRequest, "value");
      int i = Utils.string2Number(str2).intValue();
      localChartPainter.setSelectedIndex(i);
    }
  }

  public static void addMap2List(Map paramMap, String paramString)
  {
    jsMap.put(paramString, paramMap);
  }
}